<template>
    <div class='panel-container' style="">
    <row class="app-layoutpanel" style="height:100%;">
        <div v-show="detailsModel.container1.visible" class="app-layoutpanel-container" style="">
            <div style="height:100%;display: flex;">
                      
                <div v-show="detailsModel.orderflag.visible" style="" class="app-layoutpanel-field ">
                    <div class="item-field">
                    
                    <div class="item-field-content">
                    
                <app-span :value="data.orderflag" name="orderflag" :data="data" :context="context" :viewparams="viewparams" :localContext ='{ }'  :localParam ='{ }'  style=""> </app-span> 
                
                    </div>
                </div>
                
                
                </div>
                      
                <div v-show="detailsModel.emplandetailname.visible" style="" class="app-layoutpanel-field ">
                    <div class="item-field">
                    
                    <div class="item-field-content">
                    
                <app-span :value="data.emplandetailname" name="emplandetailname" :data="data" :context="context" :viewparams="viewparams" :localContext ='{ }'  :localParam ='{ }'  style=""> </app-span> 
                
                    </div>
                </div>
                
                
                </div>
                      
                <div v-show="detailsModel.equipname.visible" style="" class="app-layoutpanel-field ">
                    <div class="item-field">
                    
                    <div class="item-field-content">
                    
                <app-span :value="data.equipname" name="equipname" :data="data" :context="context" :viewparams="viewparams" :localContext ='{ }'  :localParam ='{ }'  style=""> </app-span> 
                
                    </div>
                </div>
                
                
                </div>
                      
                <div v-show="detailsModel.objname.visible" style="" class="app-layoutpanel-field ">
                    <div class="item-field">
                    
                    <div class="item-field-content">
                    
                <app-span :value="data.objname" name="objname" :data="data" :context="context" :viewparams="viewparams" :localContext ='{ }'  :localParam ='{ }'  style=""> </app-span> 
                
                    </div>
                </div>
                
                
                </div>
                      
                <div v-show="detailsModel.recvpersonname.visible" style="" class="app-layoutpanel-field ">
                    <div class="item-field">
                    
                    <div class="item-field-content">
                    
                <app-span :value="data.recvpersonname" name="recvpersonname" :data="data" :context="context" :viewparams="viewparams" :localContext ='{ }'  :localParam ='{ }'  style=""> </app-span> 
                
                    </div>
                </div>
                
                
                </div>
            </div>
        </div>
    </row>
</div>
</template>
<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch, Model,Inject } from 'vue-property-decorator';
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
import { UIActionTool,Util,ViewTool } from '@/utils';
import NavDataService from '@/service/app/navdata-service';
import AppCenterService from "@service/app/app-center-service";
import EMPlanDetailService from '@/service/emplan-detail/emplan-detail-service';
import ByPlanService from './by-plan-panel-service';
import EMPlanDetailUIService from '@/uiservice/emplan-detail/emplan-detail-ui-service';
import { FormItemModel } from '@/model/form-detail';
import ByPlanModel from './by-plan-panel-model';
import CodeListService from "@service/app/codelist-service";


@Component({
    components: {
      
    }
})
export default class ByPlanBase extends Vue implements ControlInterface {

    /**
     * 名称
     *
     * @type {string}
     * @memberof ByPlanBase
     */
    @Prop() public name?: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof ByPlanBase
     */
    @Prop() public viewState!: Subject<ViewState>;

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof ByPlanBase
     */
    @Prop() public context: any;

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof ByPlanBase
     */
    @Prop() public viewparams: any;

    /**
     * 视图状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     * @memberof ByPlanBase
     */
    public viewStateEvent: Subscription | undefined;

    /**
     * 获取部件类型
     *
     * @returns {string}
     * @memberof ByPlanBase
     */
    public getControlType(): string {
        return 'PANEL'
    }



    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof ByPlanBase
     */    
    public counterServiceArray:Array<any> = [];

    /**
     * 建构部件服务对象
     *
     * @type {ByPlanService}
     * @memberof ByPlanBase
     */
    public service: ByPlanService = new ByPlanService({ $store: this.$store });

    /**
     * 实体服务对象
     *
     * @type {EMPlanDetailService}
     * @memberof ByPlanBase
     */
    public appEntityService: EMPlanDetailService = new EMPlanDetailService({ $store: this.$store });
    


    /**
     * 转化数据
     *
     * @param {any} args
     * @memberof  ByPlanBase
     */
    public transformData(args: any) {
        let _this: any = this;
        if(_this.service && _this.service.handleRequestData instanceof Function && _this.service.handleRequestData('transform',_this.context,args)){
            return _this.service.handleRequestData('transform',_this.context,args)['data'];
        }
    }

    /**
     * 关闭视图
     *
     * @param {any} args
     * @memberof ByPlanBase
     */
    public closeView(args: any): void {
        let _this: any = this;
        _this.$emit('closeview', [args]);
    }

    /**
     *  计数器刷新
     *
     * @memberof ByPlanBase
     */
    public counterRefresh(){
        const _this:any =this;
        if(_this.counterServiceArray && _this.counterServiceArray.length >0){
            _this.counterServiceArray.forEach((item:any) =>{
                if(item.refreshData && item.refreshData instanceof Function){
                    item.refreshData();
                }
            })
        }
    }


    /**
     * 接口实现
     *
     * @returns {any[]}
     * @memberof ByPlanBase
     */
    getDatas(): any[] {
        if (!this.panelData) {
            return [];
        }
        return [this.panelData];
    }

    /**
     * 接口实现
     *
     * @returns {*}
     * @memberof ByPlanBase
     */
    getData() {
        return this.data;
    }

    /**
     * 父级部件引用
     *
     * @type {*}
     * @memberof ByPlanBase
     */
    @Prop() public parentRef?: any;

    /**
     * 面板数据对象
     *
     * @type {*}
     * @memberof ByPlanBase
     */
    @Prop() public inputData?: any;

    /**
     * 代码表服务对象
     *
     * @type {CodeListService}
     * @memberof ByPlanBase
     */
    public codeListService:CodeListService = new CodeListService({ $store:this.$store });

    /**
     * 详情模型集合
     *
     * @type {*}
     * @memberof ByPlanBase
     */
    public detailsModel: any = {
        orderflag: new FormItemModel({ visible: true, disabled: false, enableCond: 3 }), 
        emplandetailname: new FormItemModel({ visible: true, disabled: false, enableCond: 3 }), 
        equipname: new FormItemModel({ visible: true, disabled: false, enableCond: 3 }), 
        objname: new FormItemModel({ visible: true, disabled: false, enableCond: 3 }), 
        recvpersonname: new FormItemModel({ visible: true, disabled: false, enableCond: 3 }), 
        container1: new FormItemModel({ visible: true, disabled: false, enableCond: 3 }), 
    };

    /**
     * 面板逻辑
     *
     * @public
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @memberof ByPlanBase
     */
    public panelLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
                






    }

    /**
     * 数据模型对象
     *
     * @type {ByPlanModel}
     * @memberof ByPlanBase
     */
    public dataModel:ByPlanModel = new ByPlanModel();

    /**
     * UI数据对象
     *
     * @type {*}
     * @memberof ByPlanBase
     */
    public data:any = {};

    /**
     * 面板数据对象
     *
     * @type {*}
     * @memberof Mob
     */
    public panelData:any = null;

    /**
     * 监听数据对象
     *
     * @memberof ByPlanBase
     */
    @Watch('inputData',{immediate:true,deep: true})
    public onInputDataChange(newVal: any, oldVal: any){
        if(newVal){
            this.computedUIData(newVal);
            this.panelLogic({ name: '', newVal: null, oldVal: null });
            this.$forceUpdate();
        }
    }

    /**
     * 计算UI展示数据
     * 
     * @param codelistArray 代码表模型数组
     * @memberof ByPlanBase
     */
    public computedUIData(newVal:any){
        if((this.dataModel.getDataItems instanceof Function) && this.dataModel.getDataItems().length >0){
            this.dataModel.getDataItems().forEach((item:any) =>{
                this.data[item.name] = newVal[item.prop];
            })
        }
    }

    /**
     * 计算面板数据
     * 
     * @memberof Mob
     */
    public computeOutputData(){
        let panelData:any = {};
        if((this.dataModel.getDataItems instanceof Function) && this.dataModel.getDataItems().length >0){
            this.dataModel.getDataItems().forEach((item:any) =>{
                panelData[item.prop] = this.data[item.name];
            }) 
        }
        this.panelData = Object.assign(JSON.parse(JSON.stringify(this.inputData)),panelData);
    }

    /**
     * 界面行为
     *
     * @param {*} row
     * @param {*} tag
     * @param {*} $event
     * @memberof ByPlanBase
     */
    public async uiAction(row: any, tag: any, $event: any) {
        await this.computeOutputData();
    }

    /**
     * 打开编辑数据视图
     *
     * @type {any}
     * @memberof ByPlanBase
     */
    public opendata(args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any){
        if (this.parentRef.opendata && this.parentRef.opendata instanceof Function) {
            this.parentRef.opendata(args,fullargs,params, $event, xData);
        }
    }

    /**
     * 打开新建数据视图
     *
     * @type {any}
     * @memberof ByPlanBase
     */
    public newdata(args: any[],fullargs?:any[], params?: any, $event?: any, xData?: any) {
        if (this.parentRef.newdata && this.parentRef.newdata instanceof Function) {
            this.parentRef.newdata(args,fullargs,params, $event, xData);
        }
    }
    
    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
     * @memberof ByPlanBase
     */
    public async remove(datas: any[]): Promise<any> {
        if (this.parentRef.remove && this.parentRef.remove instanceof Function) {
            return this.parentRef.remove(datas);
        }
    }

    /**
     * 刷新
     *
     * @param {*} [opt={}]
     * @memberof Main
     */
    public refresh(opt: any = {}) {
        if (this.parentRef.refresh && this.parentRef.refresh instanceof Function) {
            this.parentRef.refresh(opt);
        }
    }

    
    /**
     * 设置变更面板编辑项的值
     *  
     * @param data 面板数据
     * @param {{ name: string, value: any }} $event
     * @returns {void}
     * @memberof ByPlanBase
     */
    public onPanelItemValueChange(data: any,$event: { name: string, value: any }): void {
        if (!$event) {
            return;
        }
        if (!$event.name || Object.is($event.name, '') || !data.hasOwnProperty($event.name)) {
            return;
        }
        data[$event.name] = $event.value;
        this.panelEditItemChange(data, $event.name, $event.value);
    }

    /**
     * 面板编辑项值变化后续操作
     *
     * @public
     * @param data 面板数据
     * @param property 编辑项名
     * @param value 编辑项值
     * @returns {void}
     * @memberof ByPlanBase
     */
    public panelEditItemChange(data: any, property: string, value: any){
        // 面板数据变化事件
        if((this.dataModel.getDataItems instanceof Function) && this.dataModel.getDataItems().length >0){
            let modelitem =this.dataModel.getDataItems().find((item:any) =>{
                return item.name === property;
            }) 
            if(modelitem){
                this.$emit('panelDataChange',{[modelitem.prop]: value});
            }
        }

    }

}
</script>

<style lang='less'>
@import './by-plan-panel.less';
</style>

